<template>
  <div class="bg_write">
    <el-row>
      <el-col :span="24" class="content_title">
        <el-col :span="12">
          <HeadTitle></HeadTitle>
        </el-col>
        <el-col :span="12">
        </el-col>
      </el-col>
    </el-row>
    <el-row class="pd_20">
      <el-col :span="24" class="tc">
        <div id="diy-phone" class="mgt50">
          <div class="diy-phone-header">
            <i class="diy-phone-receiver"></i>
            <div class="diy-phone-title j-pagetitle"></div>
          </div>
          <div id="j-materialPrev" class="diy-phone-contain">
            <dl class="materialPrePanel mgt20 tl">
              <div
                class="poster_con"
                :style="{backgroundImage:'url('+$fnc.getImgUrl(touxUrl)+')'}"
                style="height:800px"
              ></div>
            </dl>
          </div>
          <i class="diy-phone-footer"></i>
        </div>
        <div id="diy-ctrl " class="f_l" style="    margin-left: 12.5px;  ">
          <div class="diy-ctrl-item diy-ctrl-items o" style=" margin-top: 40px;">
            <div class="formitems">
              <el-form ref="form" :model="form">
                <el-form-item label :label-width="formLabelWidth">
                  <el-col :span="24">请填写完成下面任务所得积分，如果为0则不开放该任务</el-col>
                </el-form-item>

                <el-form-item
                  :label="item.title"
                  class="miss_input"
                  :label-width="formLabelWidth"
                  v-for="(item,i) in list"
                  :key="i"
                >
                  <el-row>
                    <!-- <el-col :span="24"> -->

                    <el-col :span="7">
                      <el-input
                        v-if="item.yz==2"
                        type="text"
                        v-Int
                        :data-type="item.iden"
                        v-model.number="item.value"
                        @change="setInput($event,item)"
                        placeholder="0"
                      ></el-input>
                      <el-input
                        v-else
                        type="text"
                        :data-type="item.iden"
                        v-model.number="item.value"
                        @change="setInput($event,item)"
                        placeholder="0"
                      ></el-input>
                    </el-col>
                    <el-col :span="10" class="tc" style="padding-left:10px">
                      <!-- {{reward}}      -->
                      <el-select
                        v-model="item.help"
                        @change="changeMiss(item.iden,item.help)"
                        placeholder="请选择金额类型"
                      >
                        <el-option
                          v-for="item in reward"
                          :key="item.id"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-col>
                    <el-col :span="7">
                      <el-switch
                        class="zdySwith"
                        :width="82"
                        v-model="item.is_open"
                        active-color="#1aad19"
                        inactive-color="#ffffff"
                        active-text="已开启"
                        inactive-text="已关闭"
                        active-value="1"
                        @change="getIskeck(item.iden,item.is_open)"
                        inactive-value="0"
                      ></el-switch>
                    </el-col>

                    <!-- </el-col> -->
                  </el-row>
                </el-form-item>
              </el-form>
            </div>
          </div>
          <i class="arrow arrow_out top150"></i>
        </div>
      </el-col>
    </el-row>
    <el-col :span="22" class="men_add">
      <el-card shadow="always">
        <el-button :loading="$store.state.isLoading" @click="addInfo" @keydown.13="addInfo">保存</el-button>
      </el-card>
    </el-col>
  </div>
</template>





<script>
import HeadTitle from "@/components/currency/HeadTitle.vue";
export default {
  components: {
    HeadTitle
  },
  data() {
    return {
      value1: true,
      value2: true,
      loadImg: false,
      formLabelWidth: "140px",
      form: {
        wcgrzl: "0",
        wcsmrz: "0",
        fxyghy: "0",
        fxypwz: "0",
        scyjsp: "0",
        yhydycnt: "0",
        wcycgwty: "0",
        pjycsp: "0",
        cyycnts: "0",
        sqyctqyj: "0"
      },
      touxUrl: require("../../assets/img/newsman.png"),
      reward: this.$store.state.rewardOption,
      list: [],
    };
  },
  methods: {
    changeMiss(iden, e) {
      var params = {};
      params.iden = iden;
      params.help = e;
      this.$api.getSettings.updateMissPay(params).then(res => {
        if (res.data.code == 200) {
          this.$message.success("修改成功！");
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    getIskeck(iden, e) {
      var params = {};
      params.iden = iden;
      params.is_open = e;
      this.$api.getSettings.updateMissCheck(params).then(res => {
        if (res.data.code == 200) {
          this.$message.success("修改成功！");
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    setInput(e, row) {
      row.value = e;
    },
    starImg() {
      this.loadImg = true;
    },
    uploadSuccess(response) {
      if (response.code == 200 && response.code_desc == "请求成功") {
        // this.$message.success("上传成功！")
        this.form.ewmbjt = this.$fnc.getImgUrl(response.result);
      } else if (response.code == 400) {
        this.$message.error("上传失败！不支持的类型");
      }
      this.loadImg = false;
    },
    uploadError(response) {
      if (response.code == 400) {
        this.$message.error("无效请求");
      }
      this.loadImg = false;
    },

    getList() {
      var params = {};
      params.cate = "news_mission";
      this.$api.getSettings.getSettingsList(params).then(res => {
        if (res.data.code == 200 && res.data.status == 1) {
          var form = {};
          this.list = res.data.result;
          var data = res.data.result;
          for (var i in data) {
            data[i].value = data[i].value == null ? 0 : data[i].value;
            form[data[i].iden] = data[i].value;
            // if(data[i].help=='' || data[i].help==null){
            //     this.list[i].help=this.reward[0].value;
            // }
          }
          this.form = form;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    addInfo() {
      var params = {};
      params.cate = "news_mission";
      params.ar = {};
      for (var i in this.list) {
        params.ar[this.list[i].iden] = this.list[i].value;
      }
      params.ar = JSON.stringify(params.ar);
      this.$api.getSettings.addMissionList(params).then(res => {
        if (res.data.code == 200 && res.data.status == 1) {
          this.$fnc.alertSuccess({ text: "修改成功" }); //成功弹出框
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
      this.loadImg = false;
    }
  },
  mounted() {
    this.getList();
  }
};
</script>
